package com.glaze.service;

import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @Description:
 * @auther ZhouLiGuo
 * @Date 2024/4/7 12:04 AM:57
 * @Version 1.0
 * @Copyright: 琉璃出品，必属精品
 */

@Service
public class distributeLock {

    @Autowired
    private RedissonClient redissonClient;

    public String discount() throws IOException {
        String key = "lock001";
        // 获取锁
        RLock lock = redissonClient.getLock(key);
        try {
            //加锁
            lock.lock();
            //TODO 执行具体业务逻辑

        }finally {
            //释放锁
            lock.unlock();
        }
        return "ok";
    }


}
